//
//  QQHHudView.m
//  FuturesNews
//
//  Created by 张伟 on 2021/3/23.
//


#import "ZWHud.h"

@implementation ZWHud

/// 弹出hud
/// @param message 要提示的文字
/// @param finish 万成回调
+ (void)showMessage:(NSString *)message finishHandle:(nullable void (^)(void))finish{
    dispatch_async(dispatch_get_main_queue(), ^{
        UIView * bgv = UIView.new;
        bgv.backgroundColor = [UIColor colorWithHexString:@"6495ED"];
        UILabel * lb = UILabel.new;
        lb.text = message;
        lb.textAlignment = NSTextAlignmentCenter;
        lb.font = [UIFont boldSystemFontOfSize:20];
        lb.textColor = [UIColor colorWithHexString:@"FFFFFF"];
        lb.numberOfLines = 0;
        [bgv addSubview:lb];
        
        CGFloat statusBarHeight = UIApplication.sharedApplication.statusBarFrame.size.height;
        
        [lb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(bgv).insets(UIEdgeInsetsMake(statusBarHeight + 5, 50, 15, 50));
        }];
        
        [WINDOW addSubview:bgv];
        [bgv mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.right.left.equalTo(WINDOW);
        }];
        
        bgv.transform = CGAffineTransformMakeTranslation(0, - KscreenHeight);
        [UIView animateWithDuration:0.5 animations:^{
            bgv.transform = CGAffineTransformIdentity;
        } completion:^(BOOL finished) {
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [UIView animateWithDuration:0.5 animations:^{
                    bgv.transform = CGAffineTransformMakeTranslation(0, -KscreenHeight);
                } completion:^(BOOL finished) {
                    [bgv removeFromSuperview];
                    if (finish) {
                        finish();
                    }
                }];
            });
        }];
    });
}




@end
